package com.jshoperxms.redis.impl;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.jshoperxms.redis.RedisBaseTDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;


@Repository("redisBaseTDao")
public class RedisBaseTDaoImpl<T> implements RedisBaseTDao<T> {
	@Autowired
	private RedisTemplate<String, T> redisTemplate;

	@Override
	public void put(String key, Object hashKey,final T t) {
		redisTemplate.opsForHash().put(key, hashKey, t);
	}

	@Override
	public T get(String key,Object hashKey) {
		return (T) redisTemplate.opsForHash().get(key, hashKey);
	}

	@Override
	public void put(String key, Object hashKey,T t, long timeout,TimeUnit timeUnit) {
		redisTemplate.opsForHash().put(key, hashKey, t);
		redisTemplate.expire(key, timeout, timeUnit);
	}

	@Override
	public void removed(String key,Class<T> cls) {
		redisTemplate.opsForHash().delete(key, key);
	}




}
